package com.xc.hotelmgr.webapi.modules.redis.controller;

import cn.hutool.core.date.DateTime;
import com.xc.hotelmgr.webapi.common.utils.PageUtils;
import com.xc.hotelmgr.webapi.common.utils.R;
import com.xc.hotelmgr.webapi.modules.redis.dto.StoreHotelInfo;
import com.xc.hotelmgr.webapi.modules.redis.service.RPRedisService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;


@RestController
@RequestMapping("rpredis")
public class RPRedisController {
    @Autowired
    RPRedisService rpRedisService;

    @RequestMapping("/storeRpSaveUseAddPriceCfg")
    public R storeRpSaveUseAddPriceCfg(@RequestBody StoreHotelInfo storeHotelInfo){
        Date stDate = DateTime.now();
        rpRedisService.storeRpSaveUseAddPriceCfg(storeHotelInfo.getStoreId(),storeHotelInfo.getAppKey(),storeHotelInfo.getHotelId());
        Date enDate = DateTime.now();
        Long diff = enDate.getTime() - stDate.getTime();
        return R.ok(diff.toString());
    }

    @RequestMapping("/delStoreRpSaveUseAddPriceCfg")
    public R delStoreRpSaveUseAddPriceCfg(@RequestBody StoreHotelInfo storeHotelInfo){
        Date stDate = DateTime.now();
        rpRedisService.delStoreRpSaveUseAddPriceCfg(storeHotelInfo.getAppKey(),storeHotelInfo.getRpList());
        Date enDate = DateTime.now();
        Long diff = enDate.getTime() - stDate.getTime();
        return R.ok(diff.toString());
    }

    @RequestMapping("/storeHtlSaveOurPlan")
    public R storeHtlSaveOurPlan(@RequestBody StoreHotelInfo storeHotelInfo){
        Date stDate = DateTime.now();
        rpRedisService.storeHtlSaveOurPlan(storeHotelInfo.getStoreId(),storeHotelInfo.getAppKey(),storeHotelInfo.getHotelId());
        Date enDate = DateTime.now();
        Long diff = enDate.getTime() - stDate.getTime();
        return R.ok(diff.toString());
    }

    @RequestMapping("/rpStoreHtlRoomSave")
    public R rpStoreHtlRoomSave(@RequestBody StoreHotelInfo storeHotelInfo){
        Date stDate = DateTime.now();
        rpRedisService.rpStoreHtlRoomSave(storeHotelInfo.getHotelId());
        Date enDate = DateTime.now();
        Long diff = enDate.getTime() - stDate.getTime();
        return R.ok(diff.toString());
    }

    @RequestMapping("/delRpStoreHtlRoomSave")
    public R delRpStoreHtlRoomSave(@RequestBody StoreHotelInfo storeHotelInfo){
        Date stDate = DateTime.now();
        rpRedisService.delRpStoreHtlRoomSave(storeHotelInfo.getRpList());
        Date enDate = DateTime.now();
        Long diff = enDate.getTime() - stDate.getTime();
        return R.ok(diff.toString());
    }

    @RequestMapping("/rpsSave")
    public R rpsSave(@RequestBody StoreHotelInfo storeHotelInfo){
        Date stDate = DateTime.now();
        rpRedisService.rpsSave(storeHotelInfo.getHotelId());
        Date enDate = DateTime.now();
        Long diff = enDate.getTime() - stDate.getTime();
        return R.ok(diff.toString());
    }
    @RequestMapping("/deleteDbRoomByHotelId")
    public R deleteDbRoomByHotelId(@RequestBody StoreHotelInfo storeHotelInfo){
        Date stDate = DateTime.now();
        rpRedisService.deleteDbRoomByHotelId(storeHotelInfo.getHotelId());
        Date enDate = DateTime.now();
        Long diff = enDate.getTime() - stDate.getTime();
        return R.ok(diff.toString());
    }

    @RequestMapping("/deleteDbRpByHotelId")
    public R deleteDbRpByHotelId(@RequestBody StoreHotelInfo storeHotelInfo){
        Date stDate = DateTime.now();
        rpRedisService.deleteDbRpByHotelId(storeHotelInfo.getHotelId());
        Date enDate = DateTime.now();
        Long diff = enDate.getTime() - stDate.getTime();
        return R.ok(diff.toString());
    }

    @RequestMapping("/deleteDbRPSByHotelId")
    public R deleteDbRPSByHotelId(@RequestBody StoreHotelInfo storeHotelInfo){
        Date stDate = DateTime.now();
        rpRedisService.deleteDbRPSByHotelId(storeHotelInfo.getHotelId());
        Date enDate = DateTime.now();
        Long diff = enDate.getTime() - stDate.getTime();
        return R.ok(diff.toString());
    }

    @RequestMapping("/deleteDbRPByIds")
    public R deleteDbRPByIds(@RequestBody StoreHotelInfo storeHotelInfo){
        Date stDate = DateTime.now();
        rpRedisService.deleteDbRPByIds(storeHotelInfo.getRpList());
        Date enDate = DateTime.now();
        Long diff = enDate.getTime() - stDate.getTime();
        return R.ok(diff.toString());
    }
}
